<template>
	<view class="container">
		<view class="head">
			<uni-icons type="redo" size="17px" style="color: #FCFCFC; float: right;margin-right: 12px;"></uni-icons>
			<uni-nav-bar dark :fixed="true" shadow background-color="#1F8AF3" color="#FCFCFC" status-bar left-icon="left" title="确认订单" @clickLeft="back(id)" />
		</view>
		<view class="main">
			<view class="userName">
				<image class="usertx" src="../../static/tx.png" mode="aspectFill"></image>
				<text class="users">柠檬精</text>
			</view>
			<view class="goods" v-for="(item,index) in goodsList" :key="index">
				<image :src="item.imgUrl" mode="aspectFit"></image>
				<view class="content">
					<text class="text3">{{item.name}}</text>
					<view class="content1">
						<text class="price">￥{{item.price}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="foot" v-for="(item,index) in goodsList" :key="index">
			<text class="price1">价格：¥{{item.price}}</text>
			<button type="primary" size="mini" class="button" @click="onclick(item.id)">确认下单</button>
		</view>
	</view>
	
</template>

<script>
	export default{
		onLoad(e) {
			this.id = e.id;
			// console.log(this.id);
		},
		created() {
			this.$axios.get("/goods/search",{
				params:{
					key:'',
				},
				headers:{
					'token':localStorage.getItem('token')
				}
			}).then(res=>{
				let key = this.id
				// console.log('key:'+key);
				res.data.data.map(item => {
				  if (item.fileType === 0) 
								item.imgUrl = '../../static/pdficon.jpeg'
				  else if (item.fileType === 1 || item.fileType ===2) 
								item.imgUrl = '../../static/docIcon.jpg'
				  else 
								item.imgUrl = '../../static/pdficon.jpeg' //默认为pdf 
				
				  item.uploadTime = new Date()
				})
				for(var i = 0; i < res.data.data.length; i++){
					if(res.data.data[i].id == key){
						this.goodsList.push(res.data.data[i])
						// console.log(111);
						
					}
				}
				// console.log(this.goodsList);
				}).catch(()=>{
					uni.showToast({
						title:"请求失败",
						icon:"none"
					})
				})
		},
		data(){
			return {
				id:'',
				goodsList:[],
			}
		},
		methods:{
			back(id){
				// 加个点击事件，返回上一页
				uni.navigateTo({
					url:'/pages/index/details?id='+id+'',
					success() {
						console.log("跳转成功")
					},
					fail() {
						console.log("跳转失败")
					}
				})
			},
			onclick(id){
				uni.navigateTo({
					url:'/pages/index/payment?id='+id+'',
					success() {
						console.log("跳转成功")
					},
					fail() {
						console.log("跳转失败")
					}
				})
			}
		}
	}
</script>

<style>
	.container{
		position: absolute;
		width: 100%;
	}
	.main{
		background-color: #FFFFFF;
		margin: 0 3px 0 6px;
		width: 100%;
		
	}
	.userName{
		display: flex;
		padding-left: 29px;
	}
	.usertx{
		width: 42px;
		height: 40px;
		border-radius: 25px 25px 25px 25px;
	}
	.users{
		font-size: 14px;
		font-weight: 700;
		color: #101010;
		margin-left: 16px;
		margin-top: 22px
	}
	.goods{
		display: flex;
		width: 100%;
		height: 120px;
		background: #fff;
		/* margin: 7px 0; */
	}
	.content1{
		margin-top: 43px;
	}
	.price{
		color: #ff0000;
		font-size: 16px;
		margin-right: 65px;
		font-weight: 700;
	}
	uni-image{
		width: 130px;
		height: 85px;
		margin-top: 15px;
	}
	.text3{
		font-size: 14px;
	}
	/* 底部 */
	.foot{
		position: fixed;  /*将一个块固定到底部*/
		bottom: 0;        /*将一个块固定到底部*/
		background-color: #FFFFFF;
		padding-bottom: 3px;
		display: flex;
		width: 100%;
	}
	.button{
		/* margin: 65px 16px 5px 229px; */
		margin-left: 44%;
		margin-top: 69px;
	}
	.price1{
		font-size: 14px;
		font-weight: 700;
		margin-left: 29px;
		margin-top: 75px;
	}
</style>